﻿<%@ Page Language="VB" MasterPageFile="~/WebForm/Empty.master" AutoEventWireup="false" CodeFile="OpenManageRoleHierarchyMapping.aspx.vb" Inherits="WebForm_ManageRole_OpenManageRoleHierarchyMapping" title="Product Authority" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript">

    //checkbox點擊事件
    function OnCheckEvent()
    {
        var objNode = event.srcElement;
        if(objNode.tagName != "INPUT" || objNode.type != "checkbox")
            {
                return;
            }
        //取得當前節點
        var ck_ID = objNode.getAttribute("ID");
        var node_ID = ck_ID.substring(0,ck_ID.indexOf("CheckBox")) + "Nodes";
        var curTreeNode = document.getElementById(node_ID);
        //連動選擇
	
//        SetChildCheckBox(curTreeNode,objNode.checked);
	$('#'+node_ID+' input:checkbox').attr('checked', objNode.checked);

        SetParentCheckBox(objNode);
    }
    
    //子節點字串
    var childIds = "";
    //取得子節點ID集合
    function GetChildIdArray(parentNode)
    {
        if (parentNode == null)
            {    
                return;
            }
        var childNodes = parentNode.children;
        var count = childNodes.length;
        for(var i = 0;i < count;i ++)
        {
            var tmpNode = childNodes[i];
            if(tmpNode.tagName == "INPUT" && tmpNode.type == "checkbox")
                {
                    childIds = tmpNode.id + ":" + childIds;
                }
            GetChildIdArray(tmpNode);
        }
    }
    
    //設置子節點的checkbox
    function SetChildCheckBox(parentNode,checked)
    {
        if(parentNode == null)
            {    
                return;
            }
        var childNodes = parentNode.children;
        var count = childNodes.length;
        for(var i = 0;i < count;i ++)
        {
            var tmpNode = childNodes[i];
            if(tmpNode.tagName == "INPUT" && tmpNode.type == "checkbox")
                {
                    tmpNode.checked = checked;
                }
            SetChildCheckBox(tmpNode,checked);
        }
    }
    
    //設置父節點的checkbox
    function SetParentCheckBox(childNode)
    {
        if(childNode == null)
            {
                return;
            }
        var parent = childNode.parentNode;
        if(parent == null || parent == "undefined")
            {
                return;
            }    
        do 
            {
                parent = parent.parentNode;
            }
        while (parent && parent.tagName != "DIV");
        if(parent == "undefined" || parent == null)
            {    
                return;
            }

        var parentId = parent.getAttribute("ID");
        var objParent = document.getElementById(parentId);

	if (parentId.indexOf('tvHierarchy')<0 && parentId.indexOf('tvIndependent')<0)
	{
		return;
	}

        childIds = "";
        //GetChildIdArray(objParent);
        //判斷子節點狀態
        //childIds = childIds.substring(0,childIds.length - 1);
        //var aryChild = childIds.split(":");
        var result = false;
        //當子節點的checkbox狀態有一個為true，其父節點checkbox狀態即為true,否則為false
        //for(var i in aryChild)
        //{
        //    var childCk = document.getElementById(aryChild[i]);
        //    if(childCk.checked)
        //        {
        //            result = true;
        //        }
        //}

result = $('#'+parentId+' input:checked').length > 0;

        parentId = parentId.replace("Nodes","CheckBox");
        var parentCk = document.getElementById(parentId);
        if(parentCk == null)
            {
                return;
            }
        if(result)
            {
                parentCk.checked = true;
            }
        else
            {
                parentCk.checked = false;
            }
        SetParentCheckBox(parentCk);
    }
    </script>

<div style="background-color: #351D26">
<asp:Panel ID="panel1" runat="server" BorderWidth="0" Style="background-color: #351D26;cursor: move;" Width="100%" Height="100%">
 <div align="center">
            <asp:Label ID="lblTitle" runat="server" Text="<%$ Resources:Title %>" SkinID="title" Font-Bold="true"></asp:Label>
 </div>
    <br /> 

        <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td align="left" colspan="2">

                    <asp:Label ID="lblViewPoint" runat="server" Text="<%$ Resources:ViewPoint %>"></asp:Label>
                    <asp:DropDownList ID="ddlViewPoint" runat="server"></asp:DropDownList>  
                    <asp:Button ID="btQuery" Text="Query"  ValidationGroup="vVPoint" runat="server"  />
                    <asp:RequiredFieldValidator ID="rfvViewPoint" runat="server" meta:resourcekey="rfvViewPoint" SetFocusOnError="true" ValidationGroup="vVPoint" ControlToValidate="ddlViewPoint" Display="None"></asp:RequiredFieldValidator>
                    <asp:ValidationSummary ID="vs3" ValidationGroup="vVPoint" runat="server" ShowMessageBox="true" ShowSummary="false"  />
                </td>
          </tr>

          <tr>
          <td valign="top">
          
                   <ajaxToolkit:TabContainer ID="AuthorityATab" CssClass="NewsTab" ActiveTabIndex="0" AutoPostBack="false" runat="server" Visible="false">
                      <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="<%$ Resources:AuthorityA %>">
                           <ContentTemplate>
                                    <table width="50%">
                                        <tr>
                                            <td>
                                                <asp:TreeView ID="tvHierarchy" runat="server" NodeStyle-ForeColor="white" ImageSet="Simple" ShowLines="true" Visible="false" ShowCheckBoxes="All">
                                                    <Nodes>
                                                        <asp:TreeNode Text="Root">
                                                        <asp:TreeNode Text="D1">
                                                            <asp:TreeNode Text="D3">
                                                            </asp:TreeNode>
                                                        </asp:TreeNode>
                                                            <asp:TreeNode Text="D2">
                                                            </asp:TreeNode>
                                                         </asp:TreeNode>
                                                    </Nodes>
                                                 </asp:TreeView>
                                            </td>
                                        </tr>
                                    </table>
                        </ContentTemplate>
                  </ajaxToolkit:TabPanel> 
                </ajaxToolkit:TabContainer> 
            </td>
            <td valign="top">
                <ajaxToolkit:TabContainer ID="AuthorityBTab" CssClass="NewsTab" ActiveTabIndex="0" AutoPostBack="false" runat="server" Visible="false">
                 <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="<%$ Resources:AuthorityB %>">
                      <ContentTemplate>
                                <table  width="50%">
                                    <tr>
                                        <td>
                                            <asp:TreeView ID="tvIndependent" runat="server" NodeStyle-ForeColor="white" ImageSet="Simple" ShowLines="true" Visible="false" ShowCheckBoxes="All">
                                                <Nodes>
                                                    <asp:TreeNode Text="Root">
                                                        <asp:TreeNode Text="D1">
                                                            <asp:TreeNode Text="D3">
                                                            </asp:TreeNode>
                                                        </asp:TreeNode>
                                                        <asp:TreeNode Text="D2">
                                                        </asp:TreeNode>
                                                     </asp:TreeNode>
                                                 </Nodes>
                                            </asp:TreeView>
                                         </td>
                                    </tr>
                                </table>
                      </ContentTemplate> 
                  </ajaxToolkit:TabPanel>
               </ajaxToolkit:TabContainer> 
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
              <asp:Button ID="btnApply" runat="server" Text="<%$ Resources:Apply %>" Visible="false" />
              <asp:Button ID="btnCancel" runat="server"  Text="<%$ Resources:Cancel %>" OnClientClick="Javascript:window.close()" />
              <br/>
           </td>
        </tr>
        </table> 

</asp:Panel> 
</div>
</asp:Content>

